package factory.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import factory.service.InterfaceContentsService;
import factory.service.InterfaceService;
import directory.interfaceDirectory.domain.InterfaceDirectoryInfo;
import interfaceManageInfo.dto.ConditionPageDTO;
import interfaceManageInfo.dto.InterfaceManageInfoDTO;
import interfaceManageInfo.vo.InterfaceManageInfoVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import result.PageDTO;
import result.R;

import java.util.List;

@Slf4j
@RestController
@Tag(name = "接口目录管理",description = "接口目录相关管理")
@RequestMapping("/interface")
public class InterfaceController {
    @Resource
    private InterfaceContentsService interfaceContentsService;
    @Resource
    private InterfaceService interfaceService;

    @Operation(summary = "查看接口目录",description = "查看接口目录")
    @PostMapping("/contents")
    public R getContents(){
        List<InterfaceDirectoryInfo> list = interfaceContentsService.list();
        return R.OK(list);
    }

    @Operation(summary = "分页查询全部接口表",description = "分页查询全部接口表")
    @PostMapping("/interface")
    public R getInterface(@RequestBody PageDTO pageDTO){
        return R.OK(interfaceService.pageListVO(pageDTO));
    }

    @Operation(summary = "根据父级id查看子目录",description = "根据父级id查看子目录")
    @GetMapping("/getChild")
    public R getChild(Integer id){
        return R.OK(interfaceContentsService.getChildContents(id));
    }


    @Operation(summary = "查询单条数据")
    @GetMapping("/getOneInterface")
    public R getOneInterface(Integer id){
        return R.OK(interfaceService.oneInterface(id));
    }

    @Operation(summary = "删除接口")
    @GetMapping("/deleteInterface")
    public R deleteInterface(Integer id){
        if(interfaceService.removeById(id)){
            return R.OK();
        }else {
            return R.FAIL();
        }
    }

    @Operation(summary = "修改接口状态")
    @GetMapping("/updateStatic")
    public R updateStatic(Integer id){
        return interfaceService.updateStatic(id)?R.OK():R.FAIL();
    }


    @Operation(summary = "条件分页查询接口表")
    @PostMapping("/pageByCondition")
    public R pageByCondition(@RequestBody ConditionPageDTO conditionPageDTO){
        Page<InterfaceManageInfoVO> infoVOPage = interfaceService.pageByCondition(conditionPageDTO);
        return R.OK(infoVOPage);
    }

    @Operation(summary = "保存并退出对应接口")
    @PostMapping("/addInterface")
    public R addInterface(@RequestBody InterfaceManageInfoDTO interfaceManageInfoDTO){
        return interfaceService.saveInterface(interfaceManageInfoDTO)?R.OK():R.FAIL();
    }

    @Operation(summary = "编辑接口")
    @PostMapping("/updateInterface")
    public R updateInterface(@RequestBody InterfaceManageInfoDTO interfaceManageInfoDTO){
        return interfaceService.updateInterface(interfaceManageInfoDTO)?R.OK():R.FAIL();
    }

}
